﻿namespace SortByAbstractClasses
{
    using System;

    /// <summary>
    /// Class for NVI template
    /// </summary>
    public abstract class SortTemplate
    {
        /// <summary>
        /// Sorts array elements
        /// </summary>
        /// <param name="array">Array of int elements</param>
        /// <param name="Criteria">Sort criteria</param>
        /// <exception cref="ArgumentNullException">If input params is null</exception>
        public void Sort(ref int[] array)
        {
            if (array == null)
                throw new ArgumentNullException();

            int temp;
            for (int i = 0; i < array.Length - 1; i++)
            {
                for (int j = i + 1; j < array.Length; j++)
                {
                    if (Criteria(array[i], array[j]))
                    {
                        temp = array[j];
                        array[j] = array[i];
                        array[i] = temp;
                    }
                }
            }
        }

        /// <summary>
        /// Sort criteria declaretion
        /// </summary>
        /// <param name="a">Value 1</param>
        /// <param name="b">Value 2</param>
        /// <returns>Bool value</returns>
        protected abstract bool Criteria(int a, int b);
    }
}
